﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SEO.Business;
using SEO.Entity;

/// <summary>
/// 编辑管理员页
/// </summary>
public partial class EditAdminInfo : AdminPage
{
    /// <summary>
    /// 页面初始化
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.EditPassword;
    }

    /// <summary>
    /// 加载数据
    /// </summary>
    protected void InitData()
    {
        lblUserName.Text = strAdminUserName;
        ltlName.Text = strAdminName;
        AdminInfo info = new BisAdminInfo().GetAdmin(nAdminUserID);
        if (info != null)
            ltlUserKey.Text = info.UserKey;
    }

    /// <summary>
    /// 提交
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtPasswords.Text.Trim() != txtComPasswords.Text.Trim())
        {
            Until.Alert("两次密码输入不一致!");
            return;
        }
        BisAdminInfo bisInfo = new BisAdminInfo();
        DataTable dt = bisInfo.GetAdminInfo(strAdminUserName);
        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["Passwords"].ToString() == Common.md5(txtOldPassword.Text.Trim()))
            {
                AdminInfo Info = new AdminInfo();
                Info.ID = nAdminUserID;
                Info.Passwords = Common.md5(txtPasswords.Text.Trim());
                bool result = bisInfo.UpdatePasswords(Info);
                Until.Alert(result ? "操作成功！" : "操作失败!");
            }
            else
            {
                Until.Alert("旧密码不正确，请重新输入！");
            }
        }
    }
}
